/*
	Authors: Andy Wu, Faiz-ur Rahman, Samuel Thacker
	Description: Main file for program.
	Revisions:
		2012/2/07 - Creation of this program file.
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
	int x = 0;
	char *input = NULL, *output = NULL;
	
/*entering while loop to check options entered*/
    while(x < argc)
	{
		/* input loop */
		if(0 == strcmp(&argv[x][0], "-i")) 
		{
			if(x < argc - 1)
			{	
				input = (char *)malloc(sizeof(char) * (strlen(&argv[x + 1][0]) + 1));
				strcpy(input, argv[x + 1]);
			}
			else
			{
				printf("Missing argument for input name!\n");
				free(input);
				free(output);
				return 5;
			}
	
			/* Moves onto next element in command */
			x += 2;
		}
		
		/* output loop */
		if(0 == strcmp(&argv[x][0], "-o"))
		{
			if(x < argc - 1)
			{	
				output = (char *)malloc(sizeof(char) * (strlen(&argv[x + 1][0]) + 1));
				strcpy(output, argv[x + 1]);
			}
			else
			{
				printf("Missing argument for output name!\n");
				free(input);
				free(output);
				return 5;
			}
			
			/* Moves onto next element in command */
			x += 2;
		}
		
		/* Moves onto next element in command */
		x++;
	}

	if(!input){
		printf("Missing argument for input name!\n");
		free(input);
		free(output);
		return 5;
	}

	if(!output){
		printf("Missing argument for output name!\n");
		free(input);
		free(output);
		return 5;
	}

	printf("input = %s and output = %s\n", input, output);
	
	free(input);
	free(output);
	return 0;
}
